package org.beanscreator.definitionreader;

import org.beanscreator.parsers.ParserFactory;
import org.beanscreator.parsers.ParserTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.modelmbean.XMLParseException;
import java.util.List;

public class XmlBeanDefinitionReaderImpl implements XmlBeanDefinitionReader {

    private static final Logger LOGGER = LoggerFactory.getLogger(XmlBeanDefinitionReaderImpl.class);

    private ParserTypes parserType = ParserTypes.DOM;
    private boolean validate = true;
    private List<ClassDefinition> classDefsList;

    @Override
    public void loadBeanDefinitions(String fileName) {
        try {
            classDefsList = ParserFactory.getParser(parserType).parse(fileName, validate);
        } catch (XMLParseException e) {
            LOGGER.error("", e);
        }
    }

    @Override
    public void setValidating(boolean validating) {
        this.validate = validating;
    }

    @Override
    public void setParserType(ParserTypes parserType) {
        this.parserType = parserType;
    }

    @Override
    public List<ClassDefinition> getClassDefsList() {
        return classDefsList;
    }
}
